package com.windfone.common;

import java.util.ArrayList;
import java.util.List;

import com.windfone.model.Pricehistory;

public class PageList {
	private static int dayNumber = 3;
	private List<Pricehistory> allRs = new ArrayList<Pricehistory>();
	private int currentPage;
	private int nextPage;
	private int prevPage;
	private int totalPage;
	public int getTotalPageNumber() {
		int rtv = allRs.size()/dayNumber ;
		if (allRs.size()%dayNumber !=0)
			rtv = rtv +1;
		return rtv;
	}
	
	public void dealPage(List<Pricehistory> ls){
		allRs = ls;
		totalPage = getTotalPageNumber();
//		int leftRecords = allRs.size()%dayNumber;
//		if ( leftRecords != 0  )
//			totalPage = totalPage + 1;
		
		if ( currentPage <= 0  ){
			currentPage = 1; 
			nextPage = 1;
			prevPage = 1;
		} else { 
			if ( currentPage>=  totalPage)
				currentPage = totalPage;
			
			if ( (currentPage-1)>0)
				prevPage = currentPage-1;
			else 
				prevPage = currentPage;
			 
			if ( currentPage+1>= totalPage )
				nextPage =  totalPage ;
			else {
				nextPage = currentPage + 1;
			}
		}
	}
	
	/**
	 * 0,1,2 == 1 | 3,4,5=2|6,7,8=3
	 * @param pointPageNumber
	 * @return
	 */
	public int[] getOnePageKeygroups(int pointPageNumber){
		List<Integer> rtvs  = new ArrayList<Integer>();
		if ( pointPageNumber >0 && pointPageNumber * dayNumber <= allRs.size() ){
			for(int i=(pointPageNumber-1);i<(pointPageNumber* dayNumber);i++)
			{
				rtvs.add( allRs.get(i ).getKeygroup() );
			}
			//1-->1*3,index-->(1-1)*3 <-->1*3-1
			//2-->2*3,index-->(2-1)*3<-->2*3-1[3,4,5]
		}
		
		if ( pointPageNumber >0 && ( (pointPageNumber-1)* dayNumber<allRs.size()) && ( pointPageNumber * dayNumber>allRs.size())){
			for(int i=(pointPageNumber-1);i<allRs.size();i++)
			{
				rtvs.add( allRs.get(i ).getKeygroup() );
			}
		}
		
		int[] rtv = new int[rtvs.size()] ;
		for(int i=0;i<rtvs.size();i++){
			rtv[i] = rtvs.get(i);
		}
		return rtv;
	}
	
	public int getCurrentPage() {
		return currentPage;
	}

	public int getNextPage() {
		return nextPage;
	}

	public int getPrevPage() {
		return prevPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	public void setPrevPage(int prevPage) {
		this.prevPage = prevPage;
	}

	public static void main(String args[]){
		int sizeNumber = 19;
		int rtv = sizeNumber/dayNumber ;
		if (sizeNumber%dayNumber !=0)
			rtv = rtv +1;
		System.out.println( rtv);
	}
}
